%Run microstructure routines to input/format data, conduct price impact
%regressions and analysis, and output results
%Uncomment this line to run microstructure analysis from beginning 
%run microstructure\main_microstructure_all;

%Analyze gap-closing sizes and welfare gains to arbitrage using main
%specification and secured lending rates (where available for analysis)
main_01_CIP;

%Create figures for main specifications
main_02_CIP_figures;

%Analyze gap-closing sizes and welfare gains to arbitrage using main
%specification and unsecured LIBOR lending rates from Du et al paper
main_03_CIP_libor;

%Create figures for all-LIBOR specifications
main_03b_CIP_figures_libor;

%Create table of summary statistics using data from the microstructure runs
main_04_CIP_summary_stats;

%Compute Gabaix and Koijen (2021)-style multipliers for output in a table
main_05_GabaixKoijen;

%Analyze gap-closing sizes and welfare gains to arbitrage using free-beta
%estimates (NLLS with exponent non-determined) instead of square root
%functional form for price impact
main_06_CIPFreeBeta;

%Analyze gap-closing sizes and welfare gains to arbitrage using
%estimates derived from fixing the beta exponent at values from 0.3 to 0.6
%instead of square root (beta=0.5) as in main text
main_06_CIPVaryingBeta;

%Create figures for free-beta routine
main_06b_CIPFreeBetaFigures;

%Create figures for varying beta routine
main_06c_CIPVaryingBetaFigures;

%Create figure that shows how changing n in P_t+n - P_t (the dependent variable) 
%changes the estimated coefficient on sign(Q_t) * Q_t
main_07_CIP_varyingNfigure;

%Compute welfare gains to arbitrage and gap-closing trade sizes for varying
%betas
main_08_CIP_welfareFiguresVaryingBeta;

clc; clear; close all;